package com.example.myapplication.moudule.mvvm;

import com.example.myapplication.base.DataResult;
import com.example.myapplication.base.mvvm.BaseViewModel;
import com.example.myapplication.base.network.rxJava.MyObserver;
import com.example.myapplication.moudule.home.repository.HomeRepository;
import com.example.myapplication.moudule.home.repository.response.HomePageData;
import com.example.myapplication.utils.LogUtils;
import com.harmonyos.livedata.LiveData;
import com.harmonyos.livedata.MutableLiveData;
import ohos.app.Context;

public class TestViewModel extends BaseViewModel {
    private HomeRepository homeModel;

    public MutableLiveData<HomePageData> homePageDataLiveData ;
    public TestViewModel(Context application) {
        super(application);
        homeModel = new HomeRepository();
        homePageDataLiveData=new MutableLiveData<HomePageData>() ;
    }

    public void getHomeData() {
        postShowLoadingNowEvent(true);
        LogUtils.info("htd", "进来");
        homeModel.optHomePage("")
                .subscribe(new MyObserver<DataResult<HomePageData>>(this) {
                    @Override
                    public void onNext(DataResult<HomePageData> homePageDataDataResult) {
                        postShowToastMessageEvent("请求成功");
                        homePageDataLiveData.postValue(homePageDataDataResult.getData());
                        LogUtils.info("htd",homePageDataDataResult.getData().list.get(0).title);
                    }
                });
    }

    @Override
    public void onCleared() {
        LogUtils.info("htd","guanbi");
        super.onCleared();
    }


}
